package com.ccp.dev.system.model;

import com.ccp.dev.core.basic.model.BaseModel;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.List;

/**
 * 子系统资源 Model对象
 *
 * @author y
 */
@XmlRootElement(name = "resource")
@XmlAccessorType(XmlAccessType.NONE)
public class Resources extends BaseModel {
    /**
     * 组织管理资源别名
     */
    public final static String USERORG_ALIAS = "zzglyj";
    /**
     * 资源默认图标
     */
    public final static String DEFAULT_ICON = "iconxiaoxi";
    /**
     * 组织管理别名
     */
    public final static String ORG_MANAGE_ALIAS = "org_manage";
    /**
     * LOGO路径
     */
    public final static String LOGO_PATH = "/styles/common/img/images/logo";
    /**
     * ICON路径
     */
    public final static String ICON_PATH = "/styles/common/img/images/resicon";
    /**
     * 图标定位路径
     */
    public final static String ICON_POSITION_PATH = "/styles/css-sprites.txt";
    /**
     * 图标类型
     */
    public final static String ICON_TYPE = "PNG|JPG|JPEG|GIF";
    /**
     * 扩展的功能按钮图标路径
     */
    public final static String ICON_EXTEND = "/styles/common/img/images/extendIcon";
    /**
     * 扩展功能样式文件位置
     */
    public final static String EXTEND_CSS_PATH = "/styles/common/css/publicStyle/form.css";

    public final static String ICON_DEFAULT_FOLDER = "/styles/common/img/images/icon/tree_folder.gif";
    public final static String ICON_DEFAULT_LEAF = "/styles/common/img/images/icon/tree_file.gif";

    /**
     * 是否公开资源0否，1是。
     */
    public final static Short IS_PUBLIC_N = 0;
    public final static Short IS_PUBLIC_Y = 1;
    /**
     * 是否公开资源
     */
    @XmlElement
    protected Short isPublic;
    /**
     * 根结点的父ID
     */
    public final static String ROOT_PID = "-1";
    /**
     * 根结点的ID
     */
    public final static String ROOT_ID = "0";

    /**
     * 根结点的icon
     */
    public final static String ROOT_ICON = "/styles/common/img/images/icon/remoteupload.gif";

    /**
     * 是否打开0否，1是。
     */
    public final static Short IS_OPEN_N = 0;
    public final static Short IS_OPEN_Y = 1;
    /**
     * 是否文件夹0否，1是
     */
    public final static Short IS_FOLDER_N = 0;
    public final static Short IS_FOLDER_Y = 1;
    /**
     * 是否显示到菜单0否，1是
     */
    public final static Short IS_DISPLAY_IN_MENU_N = 0;
    public final static Short IS_DISPLAY_IN_MENU_Y = 1;


    public final static String IS_CHECKED_N = "false";
    public final static String IS_CHECKED_Y = "true";


    /**
     * 是否打开新窗口0否，1是。
     */
    public final static Short IS_NEWOPEN_N = 0;
    public final static Short IS_NEWOPEN_Y = 1;
    /**
     * 资源id
     */
    @XmlElement
    private String resId;

    /**
     * 资源名称
     */
    @XmlElement
    private String resName;

    /**
     * 别名（系统中唯一)
     */
    @XmlElement
    private String alias;

    /**
     * 同级排序
     */
    @XmlElement
    private Integer sn;

    /**
     * 图标
     */
    @XmlElement
    private String icon;

    /**
     * 图标定位
     */
    @XmlElement
    private String iconPosition;

    /**
     * 图标 css的class属性
     */
    private String iconSkin;

    /**
     * 父ID
     */
    @XmlElement
    private String parentId;

    /**
     * 默认地址
     */
    @XmlElement
    private String defaultUrl;

    /**
     * 栏目
     */
    @XmlElement
    private Short isFolder = IS_FOLDER_N;

    /**
     * 显示到菜单
     */
    @XmlElement
    private Short isDisplayInMenu;

    /**
     * 默认打开
     */
    @XmlElement
    private Short isOpen;

    /**
     * 系统id
     */
    @XmlElement
    private String systemId;

    /**
     * 路径
     */
    @XmlElement
    private String path;
    /**
     * 创建人
     */
    @XmlElement
    private String creator;
    /**
     * 状态
     */
    @XmlElement
    private int status;

    /**
     * 用于树表显示
     */
    private String state;

    /**
     * 是否选中
     */
    @XmlElement
    private String checked = IS_CHECKED_N;

    /**
     * lay ui 判断是否被选中需要布尔值
     */
    private boolean isCheck = false;

    /**
     * 是否打开新窗口
     */
    @XmlElement
    private Short isNewOpen;

    /**
     * 角色类型  1:系统管理员 2:安全保密管理员  3：安全审计员    三员角色专用字段 标记资源属于哪个管理员
     */
    @XmlElement
    private String roleType;

    /**
     * 参数，仅用于在线表单添加为菜单时。如果为true则会同步添加在线表单的detailData_、deleteData_等url
     */
    private boolean onlineForm;
    /**
     * 表单别名
     */
    private String formKey;
    /**
     * 不是父类节点
     */
    public final static String IS_PARENT_N = "false";
    /**
     * 是父类节点
     */
    public final static String IS_PARENT_Y = "true";

    /**
     * 是否父类,主要用于树的展示时用
     */
    private String isParent;

    /**
     * 子节点数量
     */
    private int childCount;

    /**
     * 父节点的父节点id
     */
    private String parentParentId;

    /**
     * 菜单名称
     */
    private String title;
    /**
     * 子菜单
     * （子菜单 前端菜单展示与资源（菜单也是资源的一种）树展示需要的json格式里字段不同）
     */
    private List<Resources> list;
    /**
     * 资源名称 for 资源树显示名称
     */
    private String name;

    /**
     * 资源节点跳转路径 for 资源树节点
     */
    private String jump;



    /**
     * 是否正式菜单
     */
    private String  official;

    public String getOfficial() {
        return official;
    }

    public void setOfficial(String official) {
        this.official = official;
    }

    public String getRoleType() {
        return roleType;
    }

    public void setRoleType(String roleType) {
        this.roleType = roleType;
    }

    public String getIconSkin() {
        return iconSkin;
    }

    public void setIconSkin(String iconSkin) {
        this.iconSkin = iconSkin;
    }

    public boolean getIsCheck() {
        return isCheck;
    }

    public void setIsCheck(boolean check) {
        isCheck = check;
    }

    public String getTitle() {
        return resName;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public List<Resources> getList() {
        return list;
    }

    public void setList(List<Resources> list) {
        this.list = list;
    }

    public String getName() {
        if (this.creator == null || "999999999".equals(this.creator) || "999999999L".equals(this.creator)) {
            return resName + "(系统)";
        }else{
            return resName + "(" + this.creator + ")";
        }
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getJump() {
        return defaultUrl;
    }

    public void setJump(String jump) {
        this.jump = jump;
    }

    public int getChildCount() {
        return childCount;
    }

    public void setChildCount(int childCount) {
        this.childCount = childCount;
        if (childCount > 0) {
            this.isParent = IS_PARENT_Y;
        } else {
            this.isParent = IS_PARENT_N;
        }
    }

//    public String getIsParent() {
//        if(null!=this.children && this.children.size()>0){
//            return IS_PARENT_Y;
//        }
//        return IS_PARENT_N;
//    }

    public String getIsParent() {
        return isParent;
    }

    public void setIsParent(String isParent) {
        this.isParent = isParent;
    }

    public String getChecked() {
        return checked;
    }

    public void setChecked(String checked) {
        this.checked = checked;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public void setResName(String resName) {
        this.resName = resName;
    }

    public String getResName() {
        return resName;
    }

    public void setAlias(String alias) {
        this.alias = alias;
    }

    public String getAlias() {
        return alias;
    }

    public void setSn(Integer sn) {
        this.sn = sn;
    }

    public Integer getSn() {
        return sn;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public String getIcon() {
        if (icon == null || "".equals(icon)) {
            return "";
        }
        return icon;
    }

    public String getIconPosition() {
        return iconPosition;
    }

    public void setIconPosition(String iconPosition) {
        this.iconPosition = iconPosition;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public void setDefaultUrl(String defaultUrl) {
        this.defaultUrl = defaultUrl;
    }

    public String getDefaultUrl() {
        return defaultUrl;
    }

    public void setIsFolder(Short isFolder) {
        this.isFolder = isFolder;
    }

    public Short getIsFolder() {
        return isFolder;
    }

    public void setIsDisplayInMenu(Short isDisplayInMenu) {
        this.isDisplayInMenu = isDisplayInMenu;
    }

    public Short getIsDisplayInMenu() {
        return isDisplayInMenu;
    }

    public void setIsOpen(Short isOpen) {
        this.isOpen = isOpen;
    }

    public Short getIsOpen() {
        return isOpen;
    }

    public String getOpen() {
        if (isOpen != null && isOpen.shortValue() == 1) {
            return "true";
        } else {
            return "false";
        }
    }

    public Short getIsPublic() {
        return isPublic;
    }

    public void setIsPublic(Short isPublic) {
        this.isPublic = isPublic;
    }

    public String getNewOpen() {
        if (isNewOpen != null && isNewOpen.shortValue() == 1) {
            return "true";
        } else {
            return "false";
        }
    }

    public Short getIsNewOpen() {
        return isNewOpen;
    }

    public void setIsNewOpen(Short isNewOpen) {
        this.isNewOpen = isNewOpen;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public boolean isOnlineForm() {
        return onlineForm;
    }

    public void setOnlineForm(boolean onlineForm) {
        this.onlineForm = onlineForm;
    }

    public String getFormKey() {
        return formKey;
    }

    public void setFormKey(String formKey) {
        this.formKey = formKey;
    }

    public String getResId() {
        return resId;
    }

    public void setResId(String resId) {
        this.resId = resId;
    }

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    public String getSystemId() {
        return systemId;
    }

    public void setSystemId(String systemId) {
        this.systemId = systemId;
    }

    public String getCreator() {
        return creator;
    }

    public void setCreator(String creator) {
        this.creator = creator;
    }

    public String getParentParentId() {
        return parentParentId;
    }

    public void setParentParentId(String parentParentId) {
        this.parentParentId = parentParentId;
    }

    /**
     * @see Object#equals(Object)
     */
    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Resources)) {
            return false;
        }
        Resources rhs = (Resources) object;
        return new EqualsBuilder()
                .append(this.resId, rhs.resId)
                .append(this.resName, rhs.resName)
                .append(this.alias, rhs.alias)
                .append(this.sn, rhs.sn)
                .append(this.icon, rhs.icon)
                .append(this.iconPosition, rhs.iconPosition)
                .append(this.parentId, rhs.parentId)
                .append(this.defaultUrl, rhs.defaultUrl)
                .append(this.isFolder, rhs.isFolder)
                .append(this.isDisplayInMenu, rhs.isDisplayInMenu)
                .append(this.isOpen, rhs.isOpen)
                .append(this.systemId, rhs.systemId)
                .append(this.isNewOpen, rhs.isNewOpen)
                .append(this.creator, rhs.creator)
                .append(this.status, rhs.status)
                .append(this.onlineForm, rhs.onlineForm)
                .append(this.formKey, rhs.formKey)
                .append(this.tenantId, rhs.tenantId)
                .append(this.roleType, rhs.roleType)
                .append(this.isPublic, rhs.isPublic)
                .isEquals();
    }

    /**
     * @see Object#hashCode()
     */
    @Override
    public int hashCode() {
        return new HashCodeBuilder(-82280557, -700257973)
                .append(this.resId)
                .append(this.resName)
                .append(this.alias)
                .append(this.sn)
                .append(this.icon)
                .append(this.iconPosition)
                .append(this.parentId)
                .append(this.defaultUrl)
                .append(this.isFolder)
                .append(this.isDisplayInMenu)
                .append(this.isOpen)
                .append(this.systemId)
                .append(this.isNewOpen)
                .append(this.creator)
                .append(this.onlineForm)
                .append(this.formKey)
                .append(this.roleType)
                .append(this.isPublic)
                .toHashCode();
    }

    /**
     * @see Object#toString()
     */
    @Override
    public String toString() {
        return new ToStringBuilder(this)
                .append("resId", this.resId)
                .append("resName", this.resName)
                .append("alias", this.alias)
                .append("sn", this.sn)
                .append("icon", this.icon)
                .append("iconPosition", this.iconPosition)
                .append("parentId", this.parentId)
                .append("defaultUrl", this.defaultUrl)
                .append("isFolder", this.isFolder)
                .append("isDisplayInMenu", this.isDisplayInMenu)
                .append("isOpen", this.isOpen)
                .append("systemId", this.systemId)
                .append("isNewOpen", this.isNewOpen)
                .append("creator", this.creator)
                .append("status", this.status)
                .append("onlineForm", this.onlineForm)
                .append("formKey", this.formKey)
                .append("tenantId", this.tenantId)
                .append("roleType", this.roleType)
                .append("isPublic", this.isPublic)
                .toString();
    }
}